package com.eh.state.state;

import com.eh.state.base.AbstractState;
import com.eh.state.model.GumballMachine;

/**
 * Created by David on 2016/5/1.
 */
public class SoldState extends AbstractState {
    public SoldState(GumballMachine gumballMachine) {
        super(gumballMachine);
    }

    @Override
    public void dispense() {
        gumballMachine.releaseBall();
        if (gumballMachine.getCount() > 0) {
            gumballMachine.setCurrentState(gumballMachine.getNoQuarterState());
        } else {
            System.out.println("Oops, out of gumballs!");
            gumballMachine.setCurrentState(gumballMachine.getSoldOutState());
        }
    }
}
